package com.gitee.wsl.flow.sample


import com.gitee.wsl.time.Year
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.datetime.DayOfWeek
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.Month
import kotlin.time.ExperimentalTime


/*fun Flow<LocalDateTime>.filterSeconds(vararg seconds: Int) = filter { it.second in seconds }

fun Flow<LocalDateTime>.filterMinutes(vararg minutes: Int) = filter { it.minute in minutes }


fun Flow<LocalDateTime>.filterHours(vararg hours: Int) = filter { it.hour in hours }

fun Flow<LocalDateTime>.filterDaysOfMonths(vararg daysOfMonths: Int) = filter { it.dayOfMonth in daysOfMonths }

fun Flow<LocalDateTime>.filterMonths(vararg months: Month) = filter { it.month in months }
fun Flow<LocalDateTime>.filterMonths(vararg months: Int) = filter { it.monthNumber in months }


@OptIn(ExperimentalTime::class)
fun Flow<LocalDateTime>.filterYears(year: Year) = filter { it.year == year.value }
fun Flow<LocalDateTime>.filterYears(vararg years: Int) = filter { it.year in years }

fun Flow<LocalDateTime>.filterWeekDays(vararg weekDays: DayOfWeek) = filter { it.dayOfWeek in weekDays }

fun Flow<LocalDateTime>.onlyStartsOfMinutes() = filterSeconds(0)

fun Flow<LocalDateTime>.onlyStartsOfHours() = filterMinutes(0).onlyStartsOfMinutes()

fun Flow<LocalDateTime>.onlyStartsOfDays() = filterHours(0).onlyStartsOfHours()

fun Flow<LocalDateTime>.onlyStartsOfMondays() = filterWeekDays(kotlinx.datetime.DayOfWeek.MONDAY).onlyStartsOfDays()

fun Flow<LocalDateTime>.onlyStartsOfSundays() = filterWeekDays(kotlinx.datetime.DayOfWeek.SUNDAY).onlyStartsOfDays()

fun Flow<LocalDateTime>.onlyStartsOfMonths() = filterDaysOfMonths(1).onlyStartsOfDays()

fun Flow<LocalDateTime>.onlyStartsOfYears() = filterMonths(kotlinx.datetime.Month.JANUARY).onlyStartsOfMonths()
*/
//@Suppress("NOTHING_TO_INLINE")
//inline fun Flow<LocalDateTime>.filterWeekDays(vararg weekDays: Int) = filter { it.dayOfWeek.value in weekDays }

fun Flow<LocalDate>.filterDaysOfMonths(vararg daysOfMonths: Int) = filter { it.dayOfMonth in daysOfMonths }

fun Flow<LocalDate>.filterMonths(vararg months: Month) = filter { it.month in months }

fun Flow<LocalDate>.filterMonths(vararg months: Int) = filter { it.monthNumber in months }
@OptIn(ExperimentalTime::class)
fun Flow<LocalDate>.filterYears(year: Year) = filter { it.year == year.value }
fun Flow<LocalDate>.filterYears(vararg years: Int) = filter { it.year in years }

fun Flow<LocalDate>.filterWeekDays(vararg weekDays: DayOfWeek) = filter { it.dayOfWeek in weekDays }

fun Flow<LocalDate>.onlyStartsOfMondays() = filterWeekDays(kotlinx.datetime.DayOfWeek.MONDAY)

fun Flow<LocalDate>.onlyStartsOfSundays() = filterWeekDays(kotlinx.datetime.DayOfWeek.SUNDAY)

fun Flow<LocalDate>.onlyStartsOfMonths() = filterDaysOfMonths(1)

fun Flow<LocalDate>.onlyStartsOfYears() = filterMonths(kotlinx.datetime.Month.JANUARY).onlyStartsOfMonths()